package com.my.serviceimpl;

import com.my.bean.SysDic;
import com.my.bean.ZtreeBean;
import com.my.mapper.SysDicMapper;
import com.my.service.SysDicService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 字典表 服务实现类
 * </p>
 *
 * @author 张子艺
 * @since 2018-08-20
 */
@Service
public class SysDicServiceImpl extends ServiceImpl<SysDicMapper, SysDic> implements SysDicService {

    @Override
    public List<ZtreeBean> selectDic() {
        return baseMapper.selectDic();
    }

    @Override
    @Transactional
    public boolean deletAllDicById(SysDic sysDic) {
        //删除
         if (baseMapper.deleteById(sysDic.getId())>0) {
            Map map = new HashMap<>();
            map.put("parent_id", sysDic.getId());
            baseMapper.deleteByMap(map);

                return true;

        }

        return false;
    }

    @Override
    public SysDic selectDicById(long id) {
        return baseMapper.selectDicById(id);
    }

    @Override
    public List<SysDic> findDataByDicCode(String code) {

        return baseMapper.findDataByDicCode(code);
    }
}
